package top.auntie.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.auntie.bean.OrgTypeSaveDto;
import top.auntie.bean.PageReq;
import top.auntie.bean.Result;
import top.auntie.model.OrgType;
import top.auntie.model.Type;
import top.auntie.service.OrgTypeService;

import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/org/type")
public class OrgTypeController {

    @Autowired
    private OrgTypeService orgTypeService;

    @GetMapping("/query")
    public Result query(PageReq pageReq) {
        return Result.success(orgTypeService.query(pageReq));
    }

    @GetMapping("/find/type")
    public Result findTypeByOrgId(@RequestParam("id") Integer orgId) {
        return Result.success(orgTypeService.findTypeByOrgId(orgId).parallelStream().map(Type::getId).collect(Collectors.toList()));
    }

    @PostMapping("/save")
    public Result save(@RequestBody OrgTypeSaveDto orgTypeSaveDto) {
        log.debug(orgTypeSaveDto.toString());
        orgTypeService.save(orgTypeSaveDto);
        return Result.success();
    }

}
